<template>
  <div class="search">
    <!-- <h1>核赔管理</h1> -->
    <Card v-show="currView == 'index'">
      <Row v-show="openSearch" @keydown.enter.native="handleSearch">
        <Form ref="searchForm" :model="searchForm" inline :label-width="70">
          <Form-item label="保单信息" prop="userName">
            <Input
              type="text"
              v-model="searchForm.userName"
              placeholder="请输入保单号"
              clearable
              style="width: 200px"
            />
          </Form-item>
          <Form-item label="被保人信息" prop="userName">
            <Input
              type="text"
              v-model="searchForm.userName"
              placeholder="请输入用户姓名或身份证"
              clearable
              style="width: 200px"
            />
          </Form-item>
          <Form-item style="margin-left: -35px" class="br">
            <Button
              @click="handleSearch"
              type="primary"
              shape="circle"
              icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset" type="warning" shape="circle"
              >重置</Button
            >
          </Form-item>
        </Form>
      </Row>
      <Row class="operation">
        <Button
          @click="getDataList"
          type="info"
          shape="circle"
          icon="md-refresh"
          >刷新</Button
        >
        <Button type="dashed" shape="circle" @click="openTip = !openTip">{{
          openTip ? "关闭提示" : "开启提示"
        }}</Button>
      </Row>
      <Row v-show="openTip">
        <Alert show-icon>
          已选择
          <span class="select-count">{{ selectCount }}</span> 项
          <a class="select-clear" @click="clearSelectAll">清空</a>
        </Alert>
      </Row>
      <Row>
        <Table
          :loading="loading"
          border
          :columns="columns"
          :data="data"
          ref="table"
          sortable="custom"
          @on-sort-change="changeSort"
          @on-selection-change="changeSelect"
        ></Table>
      </Row>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
    <Modal
        v-model="showbox"
        title="详情"
        @on-ok="ok"
        @on-cancel="cancel">
        <p><span>保单号：</span>{{currentUserInfo.policyId}}</p>
        <p><span>被保人姓名：</span>{{currentUserInfo.name}}</p>
        <p><span>被保人身份证号：</span>{{currentUserInfo.idNo}}</p>
        <p><span>险种名：</span>{{currentUserInfo.poductName}}</p>
        <p><span>已付金额：</span>{{currentUserInfo.claimAmount}}</p>
        <p><span>赔付金额：</span>{{currentUserInfo.compensationAmount}}</p>
        <p><span>状态：</span>{{currentUserInfo.status}}</p>
    </Modal>
  </div>
</template>

<script>
import { getMeetingList,sqpfMetting } from "./api.js";
export default {
  name: "single-window",
  data() {
    return {
      currentUserInfo:{},
      showbox:false,
      openSearch: true, // 显示搜索
      openTip: true, // 显示提示
      formData: {},
      currView: "index",
      loading: true, // 表单加载状态
      searchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "createTime", // 默认排序字段
        order: "desc", // 默认排序方式
        type: "",
        userName: "",
      },
      selectList: [], // 多选数据
      selectCount: 0, // 多选计数
      columns: [
        // 表头
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          type: "index",
          width: 60,
          align: "center",
        },
        {
          title: "保单号",
          key: "policyId",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "被保人身份证号",
          key: "idNo",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "被保人姓名",
          key: "name",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "投保产品",
          key: "productName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "应赔付金额",
          key: "claimAmount",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "赔付原因",
          key: "claimReason",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "操作",
          key: "action",
          minWidth: 200,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "info",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                    display:(this.data.status ==='生效中') ? "inline-block":"none"
                  },
                  on: {
                    click: async () => {
                     let res=  await sqpfMetting(params.row.policyId)
                      // console.log(params.row.policyId);
                      // this.edit(params.row);
                    },
                  },
                },
                "申请赔付"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "warning",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                    display:(!this.data.status === '已赔付') ? "inline-block":"none"
                  },
                  on: {
                    click: () => {
                      this.showbox=!this.showbox
                      // console.log(params.row);
                      this.currentUserInfo=params.row
                      // this.remove(params.row);
                    },
                  },
                },
                "查看赔付结果"
              ),
            ]);
          },
        },
      ],
      data: [{
        id:1,
        idNo:'1',
        name:'zs',
        productName: "险种",
        claimAmount: 11,
          claimReason: "qqq",
      }], // 表单数据
      pageNumber: 1, // 当前页数
      pageSize: 10, // 页面大小
      total: 0, // 表单数据总数
    };
  },
  methods: {
    init() {
      this.getDataList();
    },
    submited() {
      this.currView = "index";
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
      this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      this.searchForm.type = "";
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    clearSelectAll() {
      this.$refs.table.selectAll(false);
    },
    changeSelect(e) {
      this.selectList = e;
      this.selectCount = e.length;
    },
    getDataList() {
      this.loading = true;
      getMeetingList(this.searchForm).then((res) => {
        console.log(res);
        this.loading = false;
          // console.log(res.result);
          // this.data=res.result
        if (res.success) {

          console.log(res.result);
          this.data = res.result;
          this.total = res.result.total;
        }
      });
    },
  },
  async mounted() {
    this.init();
  },
};
</script>

<style lang="less">
.search {
  .operation {
    margin-bottom: 2vh;
  }

  .select-count {
    font-weight: 600;
    color: #40a9ff;
  }

  .select-clear {
    margin-left: 10px;
  }

  .page {
    margin-top: 2vh;
  }

  .drop-down {
    margin-left: 5px;
  }
}
</style>